/*
 * Copyright (c) 2024 Huawei Technologies Co., Ltd.
 * openUBMC is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *         http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

#ifndef CHIP_EEPROM_H
#define CHIP_EEPROM_H

#include "internal/bus/bus_base/bus.h"
#include "internal/chip/chip_base/chip.h"
#include <mc/engine.h>
#include <memory>

constexpr uint32_t EEPROM_DEFAULT_PAGE_SIZE      = 32;
constexpr uint32_t EEPROM_MAX_PAGE_SIZE          = 1024;
constexpr uint32_t EEPROM_DEFAULT_WRITE_INTERVAL = 50;
constexpr uint32_t EEPROM_MAX_WRITE_INTERVAL     = 500;
constexpr uint16_t EEPROM_DEFAULT_FIRST_FRAG_LEN = 0;

namespace dev {

class MC_API chip_eeprom : public chip_base {
public:
    bool     init(mc::mutable_dict& csr_object);
    int32_t block_read(uint32_t offset, uint32_t length, std::vector<uint8_t>& in_buffer,
                        std::vector<uint8_t>& out_buffer, std::string& error) override;
    int32_t block_write(uint32_t offset, const std::vector<uint8_t>& in_buffer,
                         std::vector<uint8_t>& out_buffer, std::string& error) override;

private:
    uint16_t m_rw_block_size = EEPROM_DEFAULT_PAGE_SIZE; // 读写块大小
    // uint16_t m_first_frag_len = EEPROM_DEFAULT_FIRST_FRAG_LEN; // 第一个碎片长度，未使用到先注释
    uint32_t m_write_interval = EEPROM_DEFAULT_WRITE_INTERVAL; // 写间隔时间
};

} // namespace dev

#endif // CHIP_EEPROM_H